# main.py
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
import asyncio

app = FastAPI()

# 配置CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)

class StoryRequest(BaseModel):
    mode: str
    topic: str = None
    role: str = None
    scene: str = None
    text: str = None
    style: str = None
    target_pages: int = 8

@app.post("/api/generate-story")
async def generate_story(request: StoryRequest):
    # 你的故事生成逻辑
    pass

# 挂载静态文件
app.mount("/", StaticFiles(directory=".", html=True), name="static")